<template>
  <p style="display: inline-block;"
     class="base-info">基本信息：
    <el-select v-model="queryParams.collegeId"
               placeholder="--院系--"
               @change="cascade('colleges')"
               size="small">
      <el-option v-for="(item, index) in colleges"
                 :key="index"
                 :label="item.name"
                 :value="item.id">
      </el-option>
    </el-select>
    <el-select v-model="queryParams.majorId"
               placeholder="--专业--"
               @change="cascade('majors')"
               size="small">
      <el-option v-for="(item, index) in majors"
                 :key="index"
                 :label="item.name"
                 :value="item.id">
      </el-option>
    </el-select>
    <el-select v-model="queryParams.gradeName"
               placeholder="--年级--"
               @change="cascade('grades')"
               size="small">
      <el-option v-for="(item, index) in grades"
                 :key="index"
                 :label="item"
                 :value="item">
      </el-option>
    </el-select>
    <el-select v-model="queryParams.classId"
               placeholder="--班级--"
               size="small">
      <el-option v-for="(item, index) in classes"
                 :key="index"
                 :label="item.name"
                 :value="item.id">
      </el-option>
    </el-select>
    <el-select v-model="queryParams.objectOrientedName"
               size="small"
               placeholder="--学生类型--">
      <el-option v-for="(item, index) in typeList"
                 :key="index"
                 :label="item"
                 :value="item">
      </el-option>
    </el-select>
    <el-select v-model="queryParams.gender"
               size="small"
               placeholder="--性别--">
      <el-option v-for="(item, index) in sexList"
                 :key="index"
                 :label="item"
                 :value="index">
      </el-option>
    </el-select>
    <slot></slot>
  </p>
</template>
<script>
import {
  listSchoolAreaByUserUsingGET,
  listCampusBySchoolAreaIdAndUserUsingGET,
  listBuildingByCampusIdAndUserUsingGET,
  listCollegeByUserUsingGET,
  listMajorByCollegeIdUsingGET,
  listAllGradeUsingGET
  // dataDictUsingGET
} from '@api/auto'
import { getListClass } from '@api/systemManage'
export default {
  props: {
    queryParams: Object
  },
  data () {
    return {
      campus: [],
      gardens: [],
      buildings: [],
      colleges: [],
      majors: [],
      grades: [],
      classes: [],
      typeList: ['本科生', '研究生', '博士生'],
      sexList: ['未知', '男', '女'],
      cascade (type) {
        const actions = new Map([
          ['colleges', 'changeColleges'],
          ['majors', 'changeMajors'],
          ['grades', 'changeGrades']
        ])
        let temp = actions.get(type)
        this[temp]()
      },
      // 院系change
      changeColleges () {
        this.queryParams.majorId = ''
        this.queryParams.classId = ''
        this.listMajorByCollegeIdUsingGET(this.queryParams.collegeId)
        this.getListClass({ gradeName: this.queryParams.gradeName, collegeId: this.queryParams.collegeId, majorId: this.queryParams.majorId })
      },
      // 专业change
      changeMajors () {
        this.queryParams.classId = ''
        this.getListClass({ gradeName: this.queryParams.gradeName, collegeId: this.queryParams.collegeId, majorId: this.queryParams.majorId })
      },
      // 年级change
      changeGrades () {
        this.queryParams.classId = ''
        this.getListClass({ gradeName: this.queryParams.gradeName, collegeId: this.queryParams.collegeId, majorId: this.queryParams.majorId })
      }
    }
  },
  created () {
    this.listAllGradeUsingGET()
    this.listSchoolAreaByUserUsingGET()
    this.listCollegeByUserUsingGET()
    // dataDictUsingGET('object_oriented').then(res => {
    //   this.typeList = res.data
    // })
  },
  methods: {
    // 获取校区
    listSchoolAreaByUserUsingGET () {
      listSchoolAreaByUserUsingGET().then(res => {
        this.campus = res.data
      })
    },
    // 获取园区
    listCampusBySchoolAreaIdAndUserUsingGET (id) {
      listCampusBySchoolAreaIdAndUserUsingGET(id).then(res => {
        this.gardens = res.data
      })
    },
    // 获取楼栋
    listBuildingByCampusIdAndUserUsingGET (id) {
      listBuildingByCampusIdAndUserUsingGET(id).then(res => {
        this.buildings = res.data
      })
    },
    // 获取院系
    listCollegeByUserUsingGET (id) {
      listCollegeByUserUsingGET(id).then(res => {
        this.colleges = res.data
      })
    },
    // 获取专业
    listMajorByCollegeIdUsingGET (id) {
      listMajorByCollegeIdUsingGET(id).then(res => {
        this.majors = res.data
      })
    },
    // 获取年级
    listAllGradeUsingGET () {
      listAllGradeUsingGET().then(res => {
        this.grades = res.data
      })
    },
    // 获取班级
    getListClass (parmas) {
      getListClass(parmas).then(res => {
        this.classes = res.data
      })
    }
  }
}
</script>
<style lang="less">
.base-info {
  .el-select {
    margin-top: 17px;
  }
}
</style>
